package com.example.booksales.service.impl;

import com.example.booksales.core.config.BizException;
import com.example.booksales.domain.Book;
import com.example.booksales.mapper.BookMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServicelmpl implements BookService{
    private static final Logger log = LoggerFactory.getLogger(BookServicelmpl.class);
    @Autowired
    BookMapper bookMapper;
    @Override
    public List<Book> getAllBooks() {
        return bookMapper.getAllBooks();
    }
    public Book selectBookById(Long bookid) {
        Book book = bookMapper.selectBookById(bookid);
        if(book == null){
            log.error("该图书: " + bookid + " 不存在");
            throw new BizException("该图书: " + bookid + " 不存在");
        }
        log.info("查询图书: " + bookid + " 成功");
        return bookMapper.selectBookById(bookid);
    }
    @Override
    public int insertBook(Book book){
        return bookMapper.insertBook(book);
    }
    @Override
    public int updateBook(Book book){
        return bookMapper.updateBook(book);
    }
    @Override
    public int deleteBookById(Long bookid){
        return bookMapper.deleteBookById(bookid);
    }
}
